<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ProcessaAdicionarUsuario
 *
 * @author antonio
 */
class ProcessaPesquisarVoluntario extends IAbstractInterface implements IIntfacePagina {
    
    
    public $out;
    
    public function __construct($server, $banco, $login, $senha, $parametros = "") {
        parent::__construct($server, $banco, $login, $senha, $parametros);
        $this->gerarPagina();
    }
    

    public function gerarPagina() {
               
        $con  = new Conexcao($this->server,
                $this->banco,
                $this->login,
                $this->senha);
              
        $voluntarioDao = new VoluntarioDAO($con->conec);
        $horarioVoluntarioDao = new HorarioVoluntarioDAO($con->conec);
          
        //neomaliza cpf
        $temCpf = str_replace(".", "",$_POST['cpf']);
        $temCpf = str_replace("-", "",$temCpf);

        
        $voluntarioDao->consultarVoluntarioPorCpf($temCpf);

        if(count($voluntarioDao->voluntarios)> 0){
            
            $horarioVoluntarioDao->consultarHorarioVoluntario($voluntarioDao->voluntarios[0]->id);
            
                 $saida = "<table>";
                $saida .= "<tr>
                            <td>Cpf</td>
                            <td>Nome</td>
                           </tr>";

                $saida .= "<tr>
                            <td>".$voluntarioDao->voluntarios[0]->cpf."</td>
                            <td>".utf8_encode($voluntarioDao->voluntarios[0]->nome)."</td>
                           </tr>
                           </table>";     

                $saida .= "<table>";
                $saida .= "<tr>
                            <td>Dia Semana</td>
                            <td>Hora Inicio</td>
                            <td>Hora Fim</td>
                           </tr>";

                foreach ($horarioVoluntarioDao->horarioVoluntarios as $value) {

                   switch ($value->diaSemana) {

                    case 0:
                        $diaSemana = "Seg";
                        break;

                    case 1:
                        $diaSemana = "Ter";
                        break;

                    case 2:
                        $diaSemana = "Qua";
                        break;

                    case 3:
                        $diaSemana = "Qui";
                        break;

                    case 4:
                        $diaSemana = "Sex";
                        break;

                    case 5:
                        $diaSemana = "Sab";
                        break;

                    case 6:
                        $diaSemana = "Dom";
                        break;

                }      
                    //Ajusta hora inicial
                       $horaInicial = explode(" ",$value->horaInicial);
                       $horaInicial = explode(":", $horaInicial[1]);
                       $horaInicial = $horaInicial[0].":".$horaInicial[1];

                    //Ajusta hora final   
                       $horaFinal = explode(" ",$value->horaFim);
                       $horaFinal = explode(":", $horaFinal[1]);
                       $horaFinal = $horaFinal[0].":".$horaFinal[1];

                       $saida .= "<tr>
                            <td>".$diaSemana."</td>
                            <td>".$horaInicial."</td>
                            <td>".$horaFinal."</td>
                           </tr>";
                }

                $saida .= "</table>";

                $this->out = $saida;   
            
            
        }else{
            
            echo'<script >alert("Nenhum voluntario encontrado");</script>';
            $url = "http://".$_SERVER["HTTP_HOST"]."/sistema";                   
            echo'<script>window.location = "'.$url.'";</script>';        
            //echo "<meta http-equiv='refresh' content='0; url=".$url."'>";

        }
        
        
    }    //put your code here
}

?>
